<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "Salary".
 */
class Salary extends ActiveRecord {

    // @name 薪资类型
    const TypeSalary = 1;
    const TypeBonus = 2;
    public static $typeSelector = [
        self::TypeSalary => ['title' => '薪资', 'status' => 'blue'],
        self::TypeBonus => ['title' => '奖金', 'status' => 'red'],
    ];
    // @name 发放状态
    const StatusInit = 1;
    const StatusSuccess = 2;
    const StatusFaile = 3;
    public static $statusSelector = [
        self::StatusInit => ['title' => '待发放', 'status' => 'orange'],
        self::StatusSuccess => ['title' => '已发放', 'status' => 'green'],
        self::StatusFaile => ['title' => '已取消', 'status' => 'red'],
    ];

    // only define rules for those attributes that
    // will receive user inputs.
    public function rules()
    {
        return [
            [['user_id', 'employer_id', 'type', 'amount', 'date'], 'required'],
            [['user_id', 'employer_id', 'type', 'amount', 'date', 'status', 'deleted_at'], 'integer'],
            [['remark'], 'string', 'max' => 255],
        ];
    }
    /**
     * @name 字段名称
     * @return array
     */
    public function attributeLabels()
    {
        return [
            'user_id' => '设计师',
            'employer_id' => '雇主',
            'type' => '薪酬类型',
            'amount' => '金额',
            'date' => '发放日期',
            'deleted_at' => '删除时间',
            'status' => '状态',
            'remark' => '备注',
        ];
    }

    /**
     * @name 获取user信息
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }

    /**
     * @name 获取employer信息
     * @return \yii\db\ActiveQuery
     */
    public function getEmployer()
    {
        return $this->hasOne(User::className(), ['id' => 'employer_id']);
    }
}